<?php
/**
 * webappkit admin controller kit
 */
class WakAdminKit extends WakEngineKit {

    function _setUp() {
        // i18n
        $this->response->chooseLangFrom(array('en','fr'),'en');
        $this->templates->setCriteria('lang',$this->response->lang);
        // auth
        // log in
        if (!$this->realm->login(true)) {
            throw new WakEngineErrorPage("auth required",401);
        }
        // log out
        if ($_REQUEST['logout']) {
            $this->realm->logout();
            throw new WakEngineErrorPage("logged out",401);
        }
        return true;
    }

    /**
     * fallback controller
     */
    function _fallbackController() {
        // defining view
        $view=str_replace('/','.',$this->response->url->getPath());
        // checking for template
        if (!$this->templates->has($view)) {
            // no template => 404
            throw new WakEngineErrorPage("no page for $view",404);
        }

        $this->response->view=$view;
        return true;
    }/**/

    /**
     *
     */
    function index() {
        // $this->_listKits();
        return true;
    }/**/

    function kits() {
        $this->_listKits();
        return true;
    }

    /**
     * single kit administration
     * /
    function kit($id, $action=null) {

        switch ($action) {
            case 'tests': // run unit tests
                return $this->_runKitTests($this->response->kit);
                break;
            default: // home/index
                return true;
        }
    }/**/

    /**
     * help center
     * /
    function howto($topic=null) {
        return true;
    }/**/

    function _listKits() {
        // listing kits
        $ids=Webappkit::listKits();
        // getting kits configs
        foreach ($ids as $id)
            $kits[$id]=Webappkit::getCfgFromId($id);
        $this->response->kits=$kits;
    }
}
?>
